/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-12-30
 * Time: 17:04
 */

/**
 * 有20个线程，需要同时启动。
 * 每个线程按0-19的序号打印，如第一个线程需要打印0
 * 请设计代码，在main主线程中，等待所有子线程执行完后，再打印 ok
 */
public class Test2 {
    public static void main(String[] args) throws InterruptedException {
        Thread[] t = new Thread[20];

        for (int i = 0; i < 20; i++) {
            int finalI = i;
            t[i] = new Thread(() -> {
                System.out.println(finalI);
            });
        }

        for (Thread thread : t) {
            thread.start();
        }
        for (Thread thread : t) {
            thread.join();
        }

        System.out.println("OK");
    }
}
